let authCode = document.querySelector('.auth-code');

authCode.addEventListener('click', function () {
  let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789';
  let code = '';

  for (let i = 0; i < 4; i++) {
    let randomCode = Math.floor(Math.random() * chars.length);
    code += chars[randomCode];
  }
  console.log(code);

  authCode.innerHTML = `<div>${code}</div>`

});
//60s后重新获取
let phoneCode = document.querySelector('.phone-code1');
const countDown = function(){
    let num = 60;
    let timer = window.setInterval(function(){
        num --;
        phoneCode.innerText = num + 's后重新获取';
        //num=0,stop
        if(num == 0){
            //清除定时器
            window.clearInterval(timer);
            phoneCode.innerText = '获取验证码'
            //重新添加事件
            phoneCode.addEventListener('click',countDown);
        }
    },1000)
    //清除自身点击事件
    phoneCode.removeEventListener('click',countDown);
}
phoneCode.addEventListener('click',countDown);

//立即注册跳转登录
let subBtn = document.querySelector('.submit');

subBtn.addEventListener('click',function(){
    window.location.href = 'http://127.0.0.1:5501/login.html';
})

//已有账号登录
let loginBtn = document.querySelector('.header-msg span');

loginBtn.addEventListener('click',function(){
    window.location.href = 'http://127.0.0.1:5501/login.html';
})
// 页面跳转
let navLogin = document.querySelectorAll('.nav-login');

navLogin.forEach(function (item) {
  item.addEventListener('click', function () {
    window.location.href = '/login.html';
  });
})
